//
//  BMBasePickerView.m
//  bigmama
//
//  Created by huyuchen on 2017/8/15.
//  Copyright © 2017年 盛成文化. All rights reserved.
//

#import "BMBasePickerView.h"

@implementation BMBasePickerView
- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        [self prepareUI];
        [self setBackgroundColor:[UIColor whiteColor]];
        
    }
    return self;
}
- (void)prepareUI{

    UIImageView  *topBarView = [[UIImageView alloc] initWithFrame:CGRectMake(0, CGRectGetHeight(self.frame) - 44 -216, SCREEN_WIDTH, 44)];
    [topBarView setBackgroundColor:[UIColor whiteColor]];
    [topBarView setUserInteractionEnabled:YES];
    topBarView.layer.borderColor = [UIColor whiteColor].CGColor;
    topBarView.layer.borderWidth = 0.5f;
    self.topBarView = topBarView;
    [self addSubview:topBarView];
    
    self.barBtnLeft = [[UIButton alloc] initWithFrame:CGRectMake(12,5 , 48, 34)];
    [_barBtnLeft setBackgroundImage:[UIImage imageNamed:@"btn_cancel_normal.png"] forState:UIControlStateNormal];
    [_barBtnLeft.titleLabel setFont:[UIFont systemFontOfSize:16.f]];
    [topBarView addSubview:_barBtnLeft];
    
    self.barBtnRight = [[UIButton alloc] initWithFrame:CGRectMake(SCREEN_WIDTH -60,  5, 48, 34)];
    [_barBtnRight setBackgroundImage:[UIImage imageNamed:@"btn_confirm_normal.png"] forState:UIControlStateNormal];
    [_barBtnRight.titleLabel setFont:[UIFont systemFontOfSize:16.f]];
    [topBarView addSubview:_barBtnRight];
    
    self.barLblTitle = [[UILabel alloc] initWithFrame:CGRectMake(60,  5, SCREEN_WIDTH -120, 34)];
    [_barLblTitle setTextAlignment:NSTextAlignmentCenter];
    [_barLblTitle setBackgroundColor:[UIColor clearColor]];
    [_barLblTitle setTextColor:[UIColor whiteColor]];
    [topBarView addSubview:_barLblTitle];
}

- (void)setStyle:(BMPickerViewToolBarStyle)style{
    _style = style;
    
    [self changeThemeStyle:style];
    
}
- (void)changeThemeStyle:(BMPickerViewToolBarStyle)style{
    switch (style) {
        case BMPickerViewToolBarStyleIcon:
            [self.barBtnLeft setBackgroundImage:[UIImage imageNamed:@"btn_cancel_normal.png"] forState:UIControlStateNormal];
            [self.barBtnLeft setTitle:@"" forState:UIControlStateNormal];
            [self.barBtnRight setBackgroundImage:[UIImage imageNamed:@"btn_confirm_normal.png"] forState:UIControlStateNormal];
            [self.barBtnRight setTitle:@"" forState:UIControlStateNormal];
            [self.topBarView setBackgroundColor:[UIColor colorWithRed:71.0/255 green:206.0/255 blue:96.0/255 alpha:1.0]];
            self.topBarView.layer.borderColor = [UIColor colorWithRed:71.0/255 green:206.0/255 blue:96.0/255 alpha:1.0].CGColor;
            [self.barLblTitle setTextColor:[UIColor whiteColor]];
            
            break;
        case BMPickerViewToolBarStyleText:
            [self.barBtnLeft setBackgroundImage:nil forState:UIControlStateNormal];
            [self.barBtnLeft setTitle:@"取消" forState:UIControlStateNormal];
            [self.barBtnLeft setTitleColor:Color_RGB(167, 160, 157) forState:UIControlStateNormal];
            [self.barBtnRight setBackgroundImage:nil forState:UIControlStateNormal];
            [self.barBtnRight setTitle:@"确定" forState:UIControlStateNormal];
            [self.barBtnRight setTitleColor:ColorNewGreen forState:UIControlStateNormal];
            [self.topBarView setBackgroundColor:[UIColor whiteColor]];
            self.topBarView.layer.borderColor = RGB(207,207,207).CGColor;
            [self.barLblTitle setTextColor:ColorDefalutBrown];
            break;
        default:
            break;
    }
}

@end
